using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DuplicateFileFinder
{
    public partial class frmResultList : WeifenLuo.WinFormsUI.Docking.DockContent
    {
        public frmResultList()
        {
            InitializeComponent();
        }

        private Engine mEngine = null;

        public void InitViewer(Engine pEngine)
        {
            mEngine = pEngine;
            UpdateViewer();
        }

        public void UpdateViewer()
        {
   
            if (InvokeRequired)
            {
                this.Invoke(new EventManager.DelegateUpdateViewer(UpdateViewer));
            }
            else
            {
                lstView.Items.Clear();

                foreach (ResultFile tResultFile in mEngine.CompareResultList)
                {
                    AddListViewItem(tResultFile);
                }
                lstView.Columns[0].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
                lstView.Columns[1].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
                lstView.Columns[2].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
                lstView.Columns[3].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
                lstView.Columns[4].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
            }
    
        }

        private void AddListViewItem(ResultFile  pResultFile)
        {
            ListViewItem tItem = lstView.Items.Add(pResultFile.Name);
            tItem.ToolTipText = pResultFile.FileName;
 
            tItem.Tag = pResultFile;
            tItem.SubItems.Add(pResultFile.SizeLabel );
            tItem.SubItems.Add(pResultFile.Info.CreationTime.ToString());
            tItem.SubItems.Add(pResultFile.Info.LastWriteTime.ToString());
            tItem.SubItems.Add(pResultFile.Info.LastAccessTime.ToString());
        }
    }
}